home *** CD-ROM | disk | FTP | other *** search
/ Programming an RTS Game with Direct3D / Programming an RTS Game with Direct3D.iso / Examples / Chapter 5 / Example 5.10 / Debug / Shaders / terrain.vs < prev   
Encoding:
Text File  |  2006-06-22  |  1.4 KB  |  48 lines

  1. //////////////////////////////////////////////////////////////////////////
  2. //                                                                      //
  3. //                   Terrain Lighting Vertexshader                      //
  4. //                                                                      //
  5. //                   Written by C. Granberg, 2006                       //
  6. //                                                                      //
  7. //////////////////////////////////////////////////////////////////////////
  8.  
  9. uniform extern float4x4 matW;
  10. uniform extern float4x4 matVP;
  11. uniform extern float3 DirToSun;
  12.  
  13. struct VS_INPUT
  14. {
  15.    float4 position : POSITION0;
  16.    float3 normal : NORMAL0;
  17.    float2 uv : TEXCOORD0;         //alpha UV
  18.    float2 uv2 : TEXCOORD1;        //diffuse UV
  19. };
  20.  
  21. struct VS_OUTPUT
  22. {
  23.    float4 position : POSITION0;
  24.    float2 uv : TEXCOORD0;
  25.    float2 uv2 : TEXCOORD1;
  26.    float  shade : TEXCOORD2;
  27. };
  28.  
  29. VS_OUTPUT Main(VS_INPUT input)
  30. {
  31.    VS_OUTPUT output = (VS_OUTPUT)0;
  32.  
  33.    //transform World, View and Projection
  34.    float4 temp = mul(input.position, matW);
  35.    output.position = mul(temp, matVP);
  36.  
  37.    //Directional Lighting
  38.    output.shade = max(0.0f, dot(normalize(input.normal), DirToSun));
  39.    output.shade = 0.2f + output.shade * 0.8f;
  40.  
  41.    //Copy UV coordinates
  42.    output.uv = input.uv;
  43.    output.uv2 = input.uv2;
  44.  
  45.    return output;
  46. }
  47.  
  48.